<script>
	import storage from "@/utils/storage.js"
	import { saveProduction } from "@/api/quality.js"

  export default {
    onLaunch () {
			setTimeout(() => {
				plus.screen.unlockOrientation() //解除屏幕方向的锁定，但是不一定是竖屏
				plus.screen.lockOrientation('landscape-primary') //锁定横屏
				// plus.screen.lockOrientation('landscape-secondary')
			},500)
			plus.navigator.setFullscreen(false); //隐藏状态栏(应用全屏:只能隐藏状态栏，标题栏和虚拟返回键都还可以显示)
      // 加载系统信息
      this.$store.dispatch('SystemInfo')
	  
	  let systemInfo = uni.getSystemInfoSync();
	  this.systemLocale = systemInfo.language;
	  this.applicationLocale = uni.getStorageSync('lang');
	  this.isAndroid = systemInfo.platform.toLowerCase() === 'android';
	  uni.onLocaleChange((e) => {
	  	this.applicationLocale = e.locale;
	  })
	  systemInfo.language = this.applicationLocale
	  this.$store.commit('SET_SYSTEM_INFO',systemInfo)
    },
    onShow () {
			const data = uni.getStorageSync("offlineCaching")
			if (Array.isArray(data)) {
				uni.setStorageSync("offlineCaching", {})
			}
			setInterval(() => {
				const currentSewingId = storage.get('currentSewingId')
				let offlineCaching = uni.getStorageSync('offlineCaching')
				const targetList = offlineCaching[currentSewingId] || []

				if (!targetList || !targetList.length) return

				uni.request({
					url: "http://www.baidu.com",
					success: () => {
						console.log("网络状态正常~~~")
						this.isConnected = true

						while (targetList && targetList.length) {
							const params = targetList.shift()
							try {
								saveProduction(params, { custom: { loading: false } })
								if (!targetList.length) {
									offlineCaching[currentSewingId] = []
									uni.setStorageSync('offlineCaching', offlineCaching)
									console.log("准备commit CHANGE_CACHE_IDX");
									this.$store.commit('CHANGE_CACHE_IDX')
								}
							} catch (err) {
								console.log(err);
							}
						}
					},
					fail: () => {
						console.log("网络状态异常");
						this.isConnected = false
					}
				})
			}, 5000)
    },
    onHide () {
    },
  }
</script>

<style lang="scss">
@import url("@/static/icons/iconfont-weapp-icon.css");
@import "@/uni_modules/uview-ui/index.scss";
@import "@/static/style.scss";
</style>
